package com.fsserver.core.service.strategy;

import com.fsserver.common.constants.PaymentConstants;
import com.fsserver.core.dto.PaymentRequestDTO;
import com.fsserver.core.dto.ReconciliationRequestDTO;
import com.fsserver.core.dto.RefundRequestDTO;
import com.fsserver.core.entity.PaymentTransaction;
import com.fsserver.core.entity.Reconciliation;
import com.fsserver.core.entity.Refund;
import com.fsserver.core.service.PaymentStrategy;
import com.fsserver.core.vo.PaymentResponseVO;
import com.fsserver.core.vo.ReconciliationResponseVO;
import com.fsserver.core.vo.RefundResponseVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.Map;

/**
 * 默认支付策略实现
 * Default Payment Strategy Implementation
 *
 * @author fsserver
 */
@Slf4j
@Component
public class DefaultPaymentStrategy implements PaymentStrategy {

    @Override
    public String getPaymentType() {
        return PaymentConstants.PAYMENT_TYPE_OTHER;
    }

    @Override
    public PaymentResponseVO createPayment(PaymentRequestDTO paymentRequestDTO, PaymentTransaction paymentTransaction) {
        log.info("使用默认支付策略创建支付: {}", paymentRequestDTO);
        PaymentResponseVO responseVO = new PaymentResponseVO();
        responseVO.setOrderNo(paymentTransaction.getOrderNo());
        responseVO.setTransactionNo(paymentTransaction.getTransactionNo());
        responseVO.setPaymentType(paymentTransaction.getPaymentType());
        responseVO.setStatus(paymentTransaction.getStatus());
        responseVO.setPaymentUrl("https://example.com/pay");
        return responseVO;
    }

    @Override
    public PaymentTransaction queryPayment(String orderNo, String transactionNo) {
        log.info("使用默认支付策略查询支付: orderNo={}, transactionNo={}", orderNo, transactionNo);
        return null;
    }

    @Override
    public boolean closePayment(String orderNo, String transactionNo) {
        log.info("使用默认支付策略关闭支付: orderNo={}, transactionNo={}", orderNo, transactionNo);
        return true;
    }

    @Override
    public PaymentTransaction handlePaymentNotification(Map<String, String> params) {
        log.info("使用默认支付策略处理支付通知: {}", params);
        return null;
    }

    @Override
    public RefundResponseVO createRefund(RefundRequestDTO refundRequestDTO, Refund refund) {
        log.info("使用默认支付策略创建退款: {}", refundRequestDTO);
        RefundResponseVO responseVO = new RefundResponseVO();
        responseVO.setRefundNo(refund.getRefundNo());
        responseVO.setOrderNo(refund.getOrderNo());
        responseVO.setTransactionNo(refund.getTransactionNo());
        responseVO.setStatus(refund.getStatus());
        return responseVO;
    }

    @Override
    public Refund queryRefund(String refundNo) {
        log.info("使用默认支付策略查询退款: refundNo={}", refundNo);
        return null;
    }

    @Override
    public Refund handleRefundNotification(Map<String, String> params) {
        log.info("使用默认支付策略处理退款通知: {}", params);
        return null;
    }

    @Override
    public ReconciliationResponseVO createReconciliation(ReconciliationRequestDTO reconciliationRequestDTO, Reconciliation reconciliation) {
        log.info("使用默认支付策略创建对账: {}", reconciliationRequestDTO);
        ReconciliationResponseVO responseVO = new ReconciliationResponseVO();
        responseVO.setReconciliationNo(reconciliation.getReconciliationNo());
        responseVO.setReconciliationDate(reconciliation.getReconciliationDate());
        responseVO.setStatus(reconciliation.getStatus());
        return responseVO;
    }

    @Override
    public boolean executeReconciliation(Reconciliation reconciliation) {
        log.info("使用默认支付策略执行对账: {}", reconciliation);
        return true;
    }

    @Override
    public String reconciliation(Date reconciliationDate) {
        log.info("使用默认支付策略对账: reconciliationDate={}", reconciliationDate);
        return "默认对账结果";
    }
} 